<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  	<style>
  		.box {
  			width: 50%; height: 50%;
  		}
  		.input-group-addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  		#checkDelete {
  			margin-bottom: 10px;
  		}
  	</style>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header clearfix">
			<h2 class="pull-left">오늘의 파우치 관리</h2>
			<div class="pull-right" style="padding-top: 30px">
				<a href="#" id="opensearch" class="btn btn-info">오늘의 파우치 등록 펼치기/접기</a>
			</div>
		</div>
		
		<div id="searchdiv">
			<form id="insertTodayPouch" name="insertTodayPouch" class="form-horizontal" role="form" method="post">
				<fieldset>
					<div class="clearfix">
					
						<div class="box pull-left">
							<div class="form-group">
								<label for="userType" class="col-md-2 control-label">구분</label>
								<div class="col-md-9">
									<label class="radio-inline"><input type="radio" name="userType" value="USER"> 회원</label>
									<label class="radio-inline"><input type="radio" name="userType" value="ADMIN"> 에디터</label>
								</div>
							</div>
							
							<div class="form-group">
								<label for="created_date1" class="col-md-2 control-label">등록일</label>
								<div class="col-md-9 input-group input-group-sm">
									<input type="date" class="form-control" name="created_date1">
									<span class="input-group-addon">~</span>
									<input type="date" class="form-control" name="created_date2">
								</div>
							</div>
						</div>
						
						<div class="box pull-right">
							<div class="form-group">
								<label for="nickName" class="col-md-2 control-label">닉네임</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="nickName">
								</div>
							</div>
							
							<div class="form-group">
								<label for="pouchCategory" class="col-md-2 control-label">카테고리</label>
								<div class="col-md-9">
									<select class="form-control" name="pouchCategory">
										<option>--- 선택하세요 ---</option>
										<c:forEach items="${pouchCategory}" var="pouchCategory">
											<option value="${pouchCategory.idPouchCategory}">${pouchCategory.pouchCategoryText}</option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
						
						<div class="form-group">
							<div class="col-md-offset-2 col-md-8">
								<div class="row">
									<div class="col-md-6">
										<button type="submit" class="btn btn-primary btn-block" onclick='javascript:jqSubmit();'> 검색하기</button>
									</div>
									<div class="col-md-6">
										<button type="reset" class="btn btn-warning btn-block">다시작성</button>
									</div>
								</div>
							</div>
						</div>
						
					</div>
						
				</fieldset>
			</form>
			<hr/>
		</div>
		
		<span class="pull-left" style="margin-bottom:10px;">등록 : ${page.totalArticleCount}건</span>
		<div class="table-responsive">
			<form id="updateTodayPouch" class="form-horizontal" role="form" method="post" action="#">
				<table class="table table-striped table-hover">
					<thead>
						<tr class="warning row">
							<th class="text-center col-md-2">구분</th>
							<th class="text-center col-md-1">이미지</th>
							<th class="text-center col-md-2">닉네임</th>
							<th class="text-center col-md-3">파우치명</th>
							<th class="text-center col-md-1">제품수</th>
							<th class="text-center col-md-1">등록일</th>
							<th class="text-center col-md-2">옵션</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${todayPouch}" var="list">
							<tr class="text-center row">
								<td class="col-md-2">
									<c:if test="${list.userType == 'ADMIN'}">에디터</c:if>
									<c:if test="${list.userType == 'USER'}">회원</c:if>
								</td>
								<td class="col-md-1">
									<img src="download.jsp?${list.image}&size=320" class="img-thumbnail"/>
								</td>
								<td class="col-md-2">${list.idRegisterValue}</td>
								<td class="col-md-3">${list.pouchTitle}</td>
								<td class="col-md-1">${list.productCount}</td>
								<td class="col-md-1">${fn:substring(list.create_date, 0, 4)}-${fn:substring(list.create_date, 4, 6)}-${fn:substring(list.create_date, 6, 8)}</td>
								<td class="col-md-2">
									<a href="todayPouch.do?page=${page.nowPage}&id=${list.idPouch}&isToday=1">
										<button type="button" class="btn btn-sm btn-danger delToday">삭제</button>
									</a>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</form>
		</div>
		
		<div class="text-center">
			<ul class="pagination">

				<!-- 이전 그룹 -->
				<c:choose>
					<c:when test="${page.startPage > page.pageGroupCount}">
						<li><a href="todayPouch.do?page=${page.startPage-1}">&laquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&laquo;</a></li>
					</c:otherwise>
				</c:choose>
				
				<!-- 페이지 번호 -->
				<c:forEach begin="${page.startPage}" end="${page.endPage}" step="1" var="now">
					<c:choose>
						<c:when test="${page.nowPage == now}">
							<li class="active"><a href="#">${now}</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="todayPouch.do?page=${now}">${now}</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>

				<!-- 다음 그룹 -->
				<c:choose>
					<c:when test="${page.endPage < page.lastGroupFirstPage}">
						<li><a href="todayPouch.do?page=${page.endPage+1}">&raquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&raquo;</a></li>
					</c:otherwise>
				</c:choose>

			</ul>
		</div>
		
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script>
		function jqSubmit(){
			$("#insertTodayPouch").one("submit", function() {
				window.open('','pop_target','width=1000, height=700, resizable=no, status=no, menubar=no, toolbar=no, scrollbars=yes, location=no');
				this.action = "insertTodayPouch.do";
				this.method = 'POST';
				this.target = 'pop_target';
			}).trigger("submit");
		}
	
		
	
		$(function() {
			
			$("#searchdiv").hide();
			
			$("#opensearch").click(function() {
				$("#searchdiv").toggle();
				return false;
			});
			
			$(".delToday").click(function() {
				if (!confirm("정말 삭제 하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
  </body>
</html>